package com.kingint.web.portal.serve.controller;


import com.kingint.mbg.group.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;

import com.kingint.web.portal.serve.service.RoomCleanService;
import com.kingint.mbg.ser.entity.SerRoomClean;


/**
 * @描述：客房清洁单控制类
 * @作者: wxh
 * @日期: 2020-12-30
 */
@RestController
@RequestMapping("/roomClean")
@Api(value = "RoomCleanController", description = "客房清洁单")
@CrossOrigin
public class RoomCleanController {

    @Autowired
    public RoomCleanService roomCleanService;


    @ApiOperation(value = "添加客房清洁单")
    @PostMapping("/create")
    public Object create(@Validated(Insert.class) @RequestBody SerRoomClean serRoomClean) {
        String instanceid = roomCleanService.addcleanorder(serRoomClean);
        if (StringUtils.isEmpty(instanceid)) return K.error();
        return K.ok().data(instanceid);
    }

    @ApiOperation(value = "检查完成 0未完成 1已完成")
    @GetMapping("/complete")
    public Object acceptorder(@RequestParam("id") Integer serWorkOderId, @RequestParam(required = false) Integer checkstate) {
        Boolean b = roomCleanService.acceptorder(serWorkOderId, checkstate);
        return b ? K.ok() : K.error();
    }

    @ApiOperation(value = "根据编号查询客房清洁单信息")
    @GetMapping("/getRoomInfo")
    public Object getItem(@RequestParam("id") Integer id) {
        SerRoomClean serRoomClean = roomCleanService.getRoomCleanInfo(id);
        return K.ok().data(serRoomClean);
    }

    @ApiOperation(value = "清洁人员接单")
    @GetMapping("/roomCleanReceiver")
    public Object roomCleanReceiver(@RequestParam("id") Integer serWorkOderId) {
        Boolean b = roomCleanService.acceptorder1(serWorkOderId, null);
        return b ? K.ok() : K.error();
    }

    @ApiOperation(value = "清洁人员完成")
    @GetMapping("/roomCleanComplete")
    public Object roomCleanComplete(@RequestParam("id") Integer serWorkOderId) {
        Boolean b = roomCleanService.acceptorder(serWorkOderId, 3);
        return b ? K.ok() : K.error();
    }
}